<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>检查任务管理</title>
	<meta name="decorator" content="default"/>
	<script type="text/javascript">
		$(document).ready(function() {
			//$("#name").focus();
			$("#inputForm").validate({
				submitHandler: function(form){
					loading('正在提交，请稍等...');
					form.submit();
				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});
			$("#btnImport").click(function(){
				$.jBox($("#importBox").html(), {title:"导入数据", buttons:{"关闭":true}, 
					bottomText:"导入文件不能超过5M，仅允许导入“xls”或“xlsx”格式文件！"});
			});			
		});
		function addRow(list, idx, tpl, row){
			$(list).append(Mustache.render(tpl, {
				idx: idx, delBtn: true, row: row
			}));
			$(list+idx).find("select").each(function(){
				$(this).val($(this).attr("data-value"));
			});
			$(list+idx).find("input[type='checkbox'], input[type='radio']").each(function(){
				var ss = $(this).attr("data-value").split(',');
				for (var i=0; i<ss.length; i++){
					if($(this).val() == ss[i]){
						$(this).attr("checked","checked");
					}
				}
			});
		}
		function delRow(obj, prefix){
			var id = $(prefix+"_id");
			var delFlag = $(prefix+"_delFlag");
			if (id.val() == ""){
				$(obj).parent().parent().remove();
			}else if(delFlag.val() == "0"){
				delFlag.val("1");
				$(obj).html("&divide;").attr("title", "撤销删除");
				$(obj).parent().parent().addClass("error");
			}else if(delFlag.val() == "1"){
				delFlag.val("0");
				$(obj).html("&times;").attr("title", "删除");
				$(obj).parent().parent().removeClass("error");
			}
		}
	</script>
</head>
<body>
	<ul class="nav nav-tabs">
		<li class="active"><a href="${ctx}/jcxx/drJcxx/form?id=${drJcxx.id}">执法对象维护</a></li>
	</ul><br/>
    <form:form id="inputForm" modelAttribute="drJcxx" action="${ctx}/jcxx/drJcxx/zfjh_list" method="post" class="form-horizontal">
		<form:hidden path="id"/>
		<sys:message content="${message}"/>		
		<div class="control-group">
				<label class="control-label">执法对象：</label>
				<div class="controls">
					<table id="contentTable" class="table table-striped table-bordered table-condensed">
						<thead>
							<tr>
								<th class="hide"></th>
								<th>企业名称</th>
								<th>企业类型</th>
                                <th>地址</th>
                                <th>联系人</th>
                                <th>电话</th>
								<shiro:hasPermission name="jcxx:drJcxx:edit"><th width="10">&nbsp;</th></shiro:hasPermission>
							</tr>
						</thead>
						<tbody id="drJczfjlList">
						</tbody>
						<shiro:hasPermission name="jcxx:drJcxx:edit"><tfoot>
							<tr><td colspan="11"><a href="javascript:" onClick="addRow('#drJczfjlList', drJczfjlRowIdx, drJczfjlTpl);drJczfjlRowIdx = drJczfjlRowIdx + 1;" class="btn">新增</a></td></tr>
						</tfoot></shiro:hasPermission>
					</table>
					<script type="text/template" id="drJczfjlTpl">//<!--
						<tr id="drJczfjlList{{idx}}">
							<td class="hide">
								<input id="drJczfjlList{{idx}}_id" name="drJczfjlList[{{idx}}].id" type="hidden" value="{{row.id}}"/>
								<input id="drJczfjlList{{idx}}_delFlag" name="drJczfjlList[{{idx}}].delFlag" type="hidden" value="0"/>
							</td>
							<td>
								<input id="drJczfjlList{{idx}}_drZfdxDxmc" name="drJczfjlList[{{idx}}].drZfdxDxmc" type="text" value="{{row.drZfdxDxmc}}" maxlength="255" class="input-medium "/>
							</td>
							<td>
								<input id="drJczfjlList{{idx}}_remarks" name="drJczfjlList[{{idx}}]._remarks" type="text" value="{{row.remarks}}" maxlength="255" class="input-medium "/>
							</td>
							<td>
								<input id="drJczfjlList{{idx}}_sfhg" name="drJczfjlList[{{idx}}].sfhg" type="text" value="{{row.sfhg}}" maxlength="255" class="input-medium "/>
							</td>
							<td>
								<input id="drJczfjlList{{idx}}_cflx" name="drJczfjlList[{{idx}}].cflx" type="text" value="{{row.cflx}}" maxlength="255" class="input-medium "/>
							</td>
							<td>
								<input id="drJczfjlList{{idx}}_sfsxyj" name="drJczfjlList[{{idx}}].sfsxyj" type="text" value="{{row.sfsxyj}}" maxlength="255" class="input-medium "/>
							</td>																					
							<shiro:hasPermission name="jcxx:drJcxx:edit"><td class="text-center" width="10">
								{{#delBtn}}<span class="close" onclick="delRow(this, '#drJczfjlList{{idx}}')" title="删除">&times;</span>{{/delBtn}}
							</td></shiro:hasPermission>
						</tr>//-->
					</script>
					<script type="text/javascript">
						var drJczfjlRowIdx = 0, drJczfjlTpl = $("#drJczfjlTpl").html().replace(/(\/\/\<!\-\-)|(\/\/\-\->)/g,"");
						$(document).ready(function() {
							var data = ${fns:toJson(drJcxx.drJczfjlList)};
							for (var i=0; i<data.length; i++){
								addRow('#drJczfjlList', drJczfjlRowIdx, drJczfjlTpl, data[i]);
								drJczfjlRowIdx = drJczfjlRowIdx + 1;
							}
						});
					</script>
				</div>
			</div>                      
		<div class="form-actions">
			<shiro:hasPermission name="jcxx:drJcxx:edit"><input id="btnSubmit" class="btn btn-primary" type="submit" value="完成，生成执法计划"/>&nbsp;</shiro:hasPermission>
            <shiro:hasPermission name="jcxx:drJcxx:edit"><input id="btnImport" class="btn btn-primary" type="button" value="导入执法对象"/>&nbsp;</shiro:hasPermission>
			<input id="btnCancel" class="btn" type="button" value="返 回" onClick="history.go(-1)"/>
		</div>
	</form:form>
</body>
</html>